package org.apache.ws.security.message.token;


import org.apache.ws.security.util.WSSecurityUtil;
import org.apache.ws.security.WSConstants;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.Text;

public class OpenIDToken {

	protected Element element = null;
	protected Element elementOpenID = null;
	protected Element elementResponseMessage = null;
	
	

	public OpenIDToken(Document doc) {
		element = doc.createElementNS(WSConstants.WSSE_NS, "wsse:"
				+ WSConstants.OPENID_TOKEN_LN);
		WSSecurityUtil.setNamespace(element, WSConstants.WSSE_NS,
				WSConstants.WSSE_PREFIX);

		elementOpenID = doc.createElementNS(WSConstants.WSSE_NS, "wsse:"
				+ WSConstants.OPENID_LN);		
		elementOpenID.appendChild(doc.createTextNode(""));
		element.appendChild(elementOpenID);		
		
		elementResponseMessage = doc.createElementNS(WSConstants.WSSE_NS, "wsse:"
				+ WSConstants.RESPONSE_MESSAGE_LN);
		elementResponseMessage.appendChild(doc.createTextNode(""));
		element.appendChild(elementResponseMessage);
	}

	

	public void setOpenID(String openID) {
		Text node = getFirstNode(elementOpenID);
        node.setData(openID);
	}

	private Text getFirstNode(Element e) {
		Node node = e.getFirstChild();
        return ((node != null) && node instanceof Text) ? (Text) node : null;
	}	
	
	public void setResponseMessage(String responseMessage) {
		Text node = getFirstNode(elementResponseMessage);
        node.setData(responseMessage);
	}



	public Element getElement() {
		return element;
	}

}
